﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using XS.Tunnel.Cad.SteelBracing.Infrastructure;
using XS.Tunnel.Cad.SteelBracing.Infrastructure.Extensions;

namespace XS.Tunnel.Cad.SteelBracing.Component.SteelShotcrete.GrilleComponent
{
    public  class  GrilleParameter: SteelShotcreteParameter
    {

        public override SteelShotcreteType SteelShotcreteType =>  SteelShotcreteType.SteelGratingArchFrame;

        public override double ShrinkSize
        {
            get
            {
                return (Height / 2) + WallInterval;
            }
        }

        public override double InnerShrinkSize
        {
            get
            {
                return Height + WallInterval;
            }
        }

        /// <summary>
        /// 格栅的高度  
        /// </summary>
        public double Height { get; set; }
        /// <summary>
        /// 格栅分段数
        /// </summary>
        public int Subsection { get; set; }
        /// <summary>
        /// 壁间距 保护层厚度
        /// </summary>
        public double WallInterval { get; set; }
        /// <summary>
        /// 钢拱架设置范围
        /// </summary>
        public SteelShotcreteScope Scope { get; set; }
        /// <summary>
        /// 钢板
        /// </summary>
        public SteelPlateParameter WallFoot { get; set; }
        /// <summary>
        /// 角钢
        /// </summary>
        public AngleIron AngleIron { get; set; }

        /// <summary>
        /// 格栅
        /// </summary>
        public Grille Grille { get; set; }


        public override void Verification()
        {
            if (AngleIron.Height < Height)
            {
                throw XSException.Oh("格栅的高度不能大于角钢的高");
            }
            if (WallFoot.Length < Height)
            {
                throw XSException.Oh("格栅的高度不能大于墙脚连接钢板宽");
            }
        }

    }



    /// <summary>
    /// 角钢
    /// </summary>
    public class AngleIron {

        public string Color { get; set; }

        /// <summary>
        /// 高
        /// </summary>
        public double Height { get; set; }
        /// <summary>
        /// 长
        /// </summary>
        public double Length { get; set; }
        /// <summary>
        /// 厚度
        /// </summary>
        public double Thickness { get; set; }

        /// <summary>
        /// 单侧长度
        /// </summary>
        public double UnilateralLenght { 
            get
            { 
                return Length + Thickness;
            }
        }

        /// <summary>
        /// 左边的角钢
        /// </summary>
        public Polyline LeftAngleIron { get; private set; }
        /// <summary>
        /// 右边的角钢
        /// </summary>
        public Polyline RightAngleIron { get; private set; }


        /// <summary>
        /// 左边的角钢竖线
        /// </summary>
        public Line LeftAngleIronLine { get; private set; }
        /// <summary>
        /// 右边的角钢竖线
        /// </summary>
        public Line RightAngleIronLine { get; private set; }



        /// <summary>
        /// 左边的厚度
        /// </summary>
        public Line LeftThickness { get; private set; }
        /// <summary>
        /// 右边的厚度
        /// </summary>
        public Line RightThickness { get; private set; }





        public void Build(Line line)
        {
            RightAngleIron = new Polyline();
            RightAngleIron.Color = Color.ToColor();
            var rightTop= line.VerticalLine(line.StartPoint,-UnilateralLenght);
            var rightBottom = line.VerticalLine(line.EndPoint, -UnilateralLenght);
            RightAngleIron.AddVertexAt(0, rightTop.StartPoint.To2d(), 0, 0, 0);
            RightAngleIron.AddVertexAt(1, rightTop.EndPoint.To2d(), 0, 0, 0);
            RightAngleIron.AddVertexAt(2, rightBottom.EndPoint.To2d(), 0, 0, 0);
            RightAngleIron.AddVertexAt(3, rightBottom.StartPoint.To2d(), 0, 0, 0);
            RightAngleIron.AddVertexAt(4, rightTop.StartPoint.To2d(), 0, 0, 0);
            RightAngleIronLine = new Line(rightTop.EndPoint, rightBottom.EndPoint);

            LeftAngleIron = new Polyline();
            LeftAngleIron.Color = Color.ToColor();
            var leftTop = line.VerticalLine(line.StartPoint, UnilateralLenght);
            var leftBottom = line.VerticalLine(line.EndPoint, UnilateralLenght);
            LeftAngleIron.AddVertexAt(0, leftTop.StartPoint.To2d(), 0, 0, 0);
            LeftAngleIron.AddVertexAt(1, leftTop.EndPoint.To2d(), 0, 0, 0);
            LeftAngleIron.AddVertexAt(2, leftBottom.EndPoint.To2d(), 0, 0, 0);
            LeftAngleIron.AddVertexAt(3, leftBottom.StartPoint.To2d(), 0, 0, 0);
            LeftAngleIron.AddVertexAt(4, leftTop.StartPoint.To2d(), 0, 0, 0);
            LeftAngleIronLine = new Line(leftTop.EndPoint, leftBottom.EndPoint);

            var rightTopThickness = line.VerticalLine(line.StartPoint, -Thickness);
            var rightBottomThickness = line.VerticalLine(line.EndPoint, -Thickness);
            var leftTopThickness = line.VerticalLine(line.StartPoint, Thickness);
            var leftBottomThickness = line.VerticalLine(line.EndPoint, Thickness);

            RightThickness = new Line(rightTopThickness.EndPoint, rightBottomThickness.EndPoint);
            RightThickness.Color = Color.ToColor();
            LeftThickness = new Line(leftTopThickness.EndPoint, leftBottomThickness.EndPoint);
            LeftThickness.Color = Color.ToColor();
        }

    }


   
   




}
